local GameDB = import(".GameDB")


local function orderFunc( a, b )
    if a.sort and b.sort then
	   return tonumber( a.sort ) < tonumber( b.sort )
    else
        return tonumber( a.ID ) < tonumber( b.ID )
    end
end


-- 返回一级菜单全配置
function GameDB:queryDirectorySubkeyConfs()
    return self:getCachedValues("directory_subkey")
end
-- 根据 subKey 返回一级菜单一系列配置
function GameDB:queryDirectorySubkeyBySubKey( subKeyTemp )
    return self:getCachedValues("directory_subkey",
        function(v) return tonumber(v.subKey) == tonumber( subKeyTemp ) end,
        orderFunc )
end



-- 返回指南全配置
function GameDB:queryDirectoryListConfs()
    return self:getCachedValues("directory_list")
end
-- 根据 id 返回指南某一具体配置
function GameDB:queryDirectoryListById( id )
	return self:getCachedValue("directory_list",id)
end
-- 根据 dirSub 返回指南一系列配置
function GameDB:queryDirectoryListByDirSub( dirSubTemp )
    return self:getCachedValues("directory_list",
        function(v) return tonumber(v.dirSub) == tonumber( dirSubTemp ) end,
        orderFunc )
end

--日程表相关
function GameDB:getTimeLineConfigData()
    return self:getCachedValues("timeline",nil,function(a,b)
        return tonumber(a.order) < tonumber(b.order)
    end)
end

--时间线子表
function GameDB:getTimeLineSubkeyData()
    return self:getCachedValues("timeline_subkey",nil,function(a,b)
        return tonumber(a.ID) < tonumber(b.ID)
    end)
end

function GameDB:getTimeLineSubkeyById(id)
    return self:getCachedValue("timeline_subkey",id)
end


function GameDB:getDailyRoutineData()
    return self:getCachedValues("dailyroutine",nil,function(a,b)
        return tonumber(a.order) < tonumber(b.order)
    end)
end

function GameDB:getDailyRoutineDataById(id)
    return self:getCachedValue("dailyroutine",id)
end

function GameDB:getWeekRoutineData()
    return self:getCachedValues("weekroutine",nil,function(a,b)
        return tonumber(a.order) < tonumber(b.order)
    end)
end

function GameDB:getWeekRoutineDataById(id)
    return self:getCachedValue("weekroutine",id)
end

--根据战斗力获取当前所属评级
function GameDB:getDirectoryChallengeFightByPw(pw)

    local confs = self:getCachedValues("directory_challenge_fight",nil,function(a,b)
        return tonumber(a.ID) < tonumber(b.ID)
    end)
    for k,v in ipairs(confs) do
        if checknumber(v.combatMin) <= pw and checknumber(v.combatMax) >= pw then
            return v
        end
    end

    return confs[#confs]
end

--根据id获取当前的挑战
function GameDB:getDirectoryChallengeLvInfo(id)
    return self:getCachedValue("directory_challenge_LV",id)
end

function GameDB:getAllDirectoryChallengeLvInfos()
    return self:getCachedValues("directory_challenge_LV",nil,function(a,b)
        return tonumber(a.ID) < tonumber(b.ID)
    end)
end

--相关属性挑战的配置
function GameDB:getDirectoryChallengePropById(id)
    return self:getCachedValue("directory_challenge_prop",id)
end

return GameDB
